#include "Character.h"
#include "Map.h"

Character::Character()
	:mActive(true)
	,mLife(2)
	
	
{
};

Character::~Character()
{

};

void Character::Load()
{
	
	mSprite.Load("fightermain.png");
	
}; // initialize

void Character::Unload()
{
	mSprite.Unload();
}; // terminate

void Character::Update(float deltaTime, const Map& map)
{
	const float Kspeed = 600.0f;

	if(Input_IsKeyDown(Keys::D))
	{
		mPosition.x+=Kspeed * deltaTime;
	}
	else if(Input_IsKeyDown(Keys::A))
	{
		mPosition.x-=Kspeed * deltaTime;
	}
	if(Input_IsKeyDown(Keys::W))
	{
		mPosition.y-=Kspeed * deltaTime;
	}
	else if(Input_IsKeyDown(Keys::S))
	{
		mPosition.y+=Kspeed * deltaTime;
	}



	if(mPosition.x <= 0.0f - (mSprite.GetWidth() * 0.5f))
	{
		
		
		mPosition.x = map.GetWidth() - 0.1f;
		
	}

	else if(mPosition.x >= map.GetWidth() + (mSprite.GetWidth() * 0.5f))
	{
		mPosition.x = mSprite.GetWidth()/2;
	}

	
	if(mPosition.y <= 0.0f - (mSprite.GetHeight() * 0.5f))
	{
		mPosition.y = map.GetHeight() - 0.5f;
	}
	else if(mPosition.y >= map.GetHeight() + (mSprite.GetHeight() * 0.5f))
	{
		mPosition.y = 0.0f;
	}

};

void Character::Render(const SVector2& viewOffset)
{
	int width = mSprite.GetWidth();
	int height = mSprite.GetHeight();
	SVector2 offset(width * 0.5f, height * 0.5f);
	SVector2 renderPosition = mPosition - offset - viewOffset; 
	mSprite.SetPosition(renderPosition);
	mSprite.Render();
};




void Character::Kill()
{
	
	mActive=false;
}


bool Character::IsDead()
{
	if (mLife==0)
	{
		Kill();
		return true;
	}
	else
	{
	--mLife;
	return false;
	}
}

